//
//  GuessYouLikeTableViewCell.m
//  A段项目,漫画
//
//  Created by dllo on 15/4/22.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "GuessYouLikeTableViewCell.h"
#define WIDTH [[UIScreen mainScreen] bounds].size.width
//#define HEIGHT 200
@implementation GuessYouLikeTableViewCell


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.GuessData = [NSMutableArray array];
        
        self.GuessTitle = [[UILabel alloc] init];
        [self.contentView addSubview:self.GuessTitle];
        [self.GuessTitle release];
        //layout
        UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc] init];
        CGFloat bili = 200.0 / 336;
        //336  200
        flow.itemSize = CGSizeMake(WIDTH / 2.2, WIDTH / 2.2 * bili + 30);
        flow.minimumInteritemSpacing = 10;
        flow.minimumLineSpacing = 10;
        flow.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        //边距
        flow.sectionInset = UIEdgeInsetsMake(5, 15, 5, 10);
        
        self.GuessCollection = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 40, WIDTH, WIDTH / 2.2 * bili + 40) collectionViewLayout:flow];
        [self.contentView addSubview:self.GuessCollection];
        self.GuessCollection.delegate = self;
        self.GuessCollection.dataSource = self;
        //注册
        [self.GuessCollection registerClass:[GuessYouLikeCollectionViewCell class] forCellWithReuseIdentifier:@"reuseCollectionManga"];
        self.GuessCollection.backgroundColor = [UIColor whiteColor];
    }
    return self;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    ComicListData *cd = self.GuessData[indexPath.row];
    [self.delegate getGuessYouLikeID:cd.comic_id];
}

-(void)layoutSubviews{
    [super layoutSubviews];
    self.GuessTitle.frame = CGRectMake(0, 0, WIDTH, 40);
    self.GuessTitle.backgroundColor = [UIColor colorWithRed:244 / 255.0 green:244 / 255.0 blue:244 / 255.0 alpha:1];
    self.GuessTitle.layer.borderWidth = 5;
    self.GuessTitle.layer.cornerRadius = 10;
    self.GuessTitle.layer.borderColor = [UIColor clearColor].CGColor;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.GuessData.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    GuessYouLikeCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"reuseCollectionManga" forIndexPath:indexPath];
    ComicListData *cd = self.GuessData[indexPath.row];
    NSURL *url = [NSURL URLWithString:cd.cover_url];
    UIImage *placeImage = [UIImage imageNamed:@"FOR@{XC4(JCI7}{P@Y]({{1－1（被拖移）.tiff"];
    [cell.GuessImage sd_setImageWithURL:url placeholderImage:placeImage];
    cell.imageLabel.text = cd.title;
    return cell;
}



- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
